package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.pro.ProductionOrder;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pro.service.ProductionOrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/productionOrder")
public class ProductionOrderController {

    @Autowired
    private ProductionOrderService productionOrderService;

    /**
     * 接口1：多条件分页查询工单列表
     * GET /productionOrder/list
     */
    @GetMapping("/page")
    public Result<PageInfo<ProductionOrder>> list(ProductionOrder productionOrder,
                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                  @RequestParam(defaultValue = "10") Integer pageSize) {
        // 分页参数
        return productionOrderService.list(productionOrder, pageNum, pageSize);
    }

    //根据工单ID查询单个工单信息
    @GetMapping("/{id}")
    public Result<ProductionOrder> selectById(@PathVariable Long id) {
        return productionOrderService.selecById(id);
    }

    //新增工单
    @PostMapping("/add")
    public Result<ProductionOrder> add(@RequestBody ProductionOrder productionOrder) {
        return productionOrderService.add(productionOrder);
    }

    //根据工单编号编辑工单信息
    @PutMapping("/update")
    public Result<ProductionOrder> update(ProductionOrder productionOrder) {
        return productionOrderService.updateById(productionOrder);
    }

    //根据工单编号删除工单信息
    @DeleteMapping("/delete/{id}")
    public Result<ProductionOrder> deleteById(@PathVariable Long id) {
        return productionOrderService.deleteById(id);
    }



}

